package com.jservice.web.smkSms;

import com.jservice.framework.dto.Order;
import com.jservice.framework.dto.Pageable;
import com.jservice.framework.dto.Pager;
import com.jservice.framework.idWorker.Sequence;
import com.jservice.framework.spring.SpringContextUtil;
import com.jservice.model.SmkSms;
import com.jservice.web.base.JBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * smsService
 *
 * @Author cwledit
 * @DATE 2017/6/21.
 */
@Service("smsService")
@Transactional(readOnly = true)
public class SmsService extends JBaseService{

    public static final SmkSms DAO = new SmkSms();

    public static SmsService me() {
        return SpringContextUtil.getBean("smsService");
    }

    @Resource
    private Sequence sequence;

    public Pager findPage(Pageable pageable) {
        Order order1 = new Order();
        order1.setProperty("create_date");
        order1.setDirection(Order.Direction.desc);

        pageable.getOrders().add(order1);
        return findPage(pageable,DAO, SmkSms.TABLE_NAME);
    }

    /**
     *
     * @param account 账号
     * @param message 通知消息
     * @return
     */
    @Transactional(readOnly = false)
    public boolean save(String account, String message){
        SmkSms smkSms = new SmkSms();
        smkSms.setId(sequence.nextIdStr());
        smkSms.setCreateDate(new Date());
        smkSms.setModifyDate(new Date());
        smkSms.setStatus("0");
        smkSms.setAccount(account);
        smkSms.setMessage(message);
        return smkSms.save();
    }

}
